package com.cherish.meeting.common.util;

import java.util.Calendar;

/**
 * @author admin
 */
public class CalendarUtil {

    private static final String timeSplit = ":";
    private static final String dateSplit = "-";

    public static void main(String[] args) {
        System.out.println(strToDate("2020-02-28"));
        System.out.println(strToTime("12:12:12"));
        System.out.println(getNowTime());
        System.out.println(getNowDate());
    }

    public static String getNowDate() {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return year + dateSplit + month + dateSplit + day;
    }

    public static java.sql.Time getNowSqlTime() {
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        return new java.sql.Time(hour, minute, second);
    }

    public static String getNowTime() {
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        return hour + timeSplit + minute + timeSplit + second;
    }

    public static java.sql.Date strToDate(String dateStr) {
        return java.sql.Date.valueOf(dateStr);
    }

    public static java.sql.Time strToTime(String timeStr) {
        if (timeStr.split(timeSplit).length == 2) {
            timeStr = timeStr + ":00";
        }
        return java.sql.Time.valueOf(timeStr);
    }


}
